package com.smartwebx.ha.util;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
/**
 *类描述：
 * 
 * @author: 程子清
 *@date： 日期：2011-1-11 时间：上午10:12:25
 *@version 1.0
 */
public class VisoLine {
	private String path;

	public String getPath() {
		return path;
	}

	public VisoLine() throws IOException {
		/*path = PathTools.getPathFromClass(PathTools.class).substring(0,
				PathTools.getPathFromClass(PathTools.class).indexOf("WEB-INF"))
				+ "emf2vec\\";*/
		path="D:\\vistech\\apache-tomcat-6.0.39\\webapps\\appServices\\emf2vec\\";
		System.out.println(path);
	}
	/**
	 * 绘制
	 * @param srcPath
	 * @param title
	 * @param id
	 * @throws IOException
	 */
	public void drawit(String srcPath,String title,String dataForm, String lineNum,String id,String areaBln) throws IOException {
		ComThread.InitSTA();
		ActiveXComponent isoline = new ActiveXComponent("Visoline.App");
		Dispatch msg = isoline.getObject();
		Dispatch.call(msg, "setKey", new Variant("边界属性"), new Variant("剪切文件"), new Variant(areaBln));
		if(dataForm.equals("selfSet")){
			Dispatch.call(msg, "setKey", new Variant("线条属性"), new Variant("线条来源"), new Variant(2));
			Dispatch.call(msg, "setKey", new Variant("线条属性"), new Variant("线条序列"), new Variant(lineNum));
			Dispatch.call(msg, "setKey", new Variant("分布属性"), new Variant("分布序列"), new Variant(lineNum));
		}else{
			Dispatch.call(msg, "setKey", new Variant("线条属性"), new Variant("线条来源"), new Variant(0));
		}
		if(id.indexOf("visoface")>-1){
			Dispatch.call(msg, "drawit", new Variant(srcPath), new Variant(1),
					new Variant(1), new Variant(""), new Variant(1),new Variant(title),new Variant(""),new Variant(""));
		}
		if(id.indexOf("visobow")>-1){
			Dispatch.call(msg, "drawit", new Variant(srcPath), new Variant(1),
					new Variant(2), new Variant(""), new Variant(1),new Variant(title),new Variant(""),new Variant(""));
		}
		if(id.indexOf("visoline")>-1){
			Dispatch.call(msg, "drawit", new Variant(srcPath), new Variant(1),
					new Variant(3), new Variant(""), new Variant(1),new Variant(title),new Variant(""),new Variant(""));
		}
		ComThread.Release();
		String cmd = "cmd /c D:/vistech/apache-tomcat-6.0.39/webapps/appServices/emf2vec/ "+id+".kml "+id+".swf -unicode";
		Runtime.getRuntime().exec(cmd, new String[]{}, new File("d:/"));
	}
	/**
	 * 生成符合格式的数据文件
	 * @param id
	 * @param src
	 * @return
	 * @throws IOException
	 */
	public String getsrcPath(String id,String[][] src) throws IOException {
		String strPath = "d:/app.dat";
		File file = new File(strPath);
		if (!file.exists()) {
			file.createNewFile();
		} else {
			file.delete();
			file.createNewFile();
		}
		FileWriter fileWriter = new FileWriter(strPath, true);
		String nextLine = System.getProperty("line.separator");
		int index = 1;
		for (String[] row : src) {
			if(row!=null && !row[0].toString().equals("")){
				for (String str : row) {
					fileWriter.append(str + "        ");
				}
				fileWriter.write(nextLine);
			}
		}
		fileWriter.flush();
		fileWriter.close();
		return strPath;
	}

	public static void main(String[] args) throws IOException {
		VisoLine visoLine = new VisoLine();
		String[][] src = {
				{ "118.9758", "31.6381", "963.9", "62703100", "62703100963.9" },
				{ "119.9167", "31.3167", "942.1", "63201050", "63201050942.1" },
				{ "118.8194", "31.9522", "917.8", "62702350", "62702350917.8" },
				{ "119.0709", "31.8597", "912", "62702801", "62702801912" },
				{ "119.3836", "32.2174", "904.4", "60116601", "60116601904.4" },
				{ "118.8383", "32.3395", "904.3", "62914800", "62914800904.3" },
				{ "119.5912", "31.9791", "903.5", "63202600", "63202600903.5" },
				{ "119.5667", "31.25", "889.1", "63101901", "63101901889.1" },
				{ "118.8606", "31.3208", "883.8", "62912800", "62912800883.8" },
				{ "118.7332", "32.0841", "883.6", "60116200", "60116200883.6" },
				{ "118.7969", "32.0161", "875.4", "62702451", "62702451875.4" },
				{ "120.4524", "32.5446", "874.3", "51006150", "51006150874.3" },
				{ "118.5461", "32.1569", "870.1", "62914200", "62914200870.1" },
				{ "119.3259", "31.4413", "869.6", "63101151", "63101151869.6" },
				{ "119.8", "31.3667", "868.2", "63101300", "63101300868.2" },
				{ "119.4939", "31.4262", "853.8", "63101200", "63101200853.8" } };
		String ss="[[\"118.9758\",\"31.6381\",\"963.9\",\"62703100\",\"62703100963.9\"],[\"119.9167\",\"31.3167\",\"942.1\",\"63201050\",\"63201050942.1\"],[\"118.8194\",\"31.9522\",\"917.8\",\"62702350\",\"62702350917.8\"],[\"119.0709\",\"31.8597\",\"912\",\"62702801\",\"62702801912\"],[\"119.3836\",\"32.2174\",\"904.4\",\"60116601\",\"60116601904.4\"],[\"118.8383\",\"32.3395\",\"904.3\",\"62914800\",\"62914800904.3\"],[\"119.5912\",\"31.9791\",\"903.5\",\"63202600\",\"63202600903.5\"],[\"119.5667\",\"31.25\",\"889.1\",\"63101901\",\"63101901889.1\"],[\"118.8606\",\"31.3208\",\"883.8\",\"62912800\",\"62912800883.8\"],[\"118.7332\",\"32.0841\",\"883.6\",\"60116200\",\"60116200883.6\"],[\"118.7969\",\"32.0161\",\"875.4\",\"62702451\",\"62702451875.4\"],[\"120.4524\",\"32.5446\",\"874.3\",\"51006150\",\"51006150874.3\"],[\"118.5461\",\"32.1569\",\"870.1\",\"62914200\",\"62914200870.1\"],[\"119.3259\",\"31.4413\",\"869.6\",\"63101151\",\"63101151869.6\"],[\"119.8\",\"31.3667\",\"868.2\",\"63101300\",\"63101300868.2\"],[\"119.4939\",\"31.4262\",\"853.8\",\"63101200\",\"63101200853.8\"]]";
		/*Gson gson=new Gson();
		
		
		
		String s=gson.toJson(src);
		String[][] srcs=gson.fromJson(ss,String[][].class);
		System.out.println(s);*/
		//visoLine.drawit(visoLine.getsrcPath(srcs));
		/*visoLine.drawit(visoLine.getsrcPath("test1",src),"title","visobow","江苏边界.bln");*/
//		System.out.println(visoLine.getsrcPath(src));
		System.exit(0);
	}
}
